package parsers;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class FileParser {

	/**
	 * Parses a set of firewall rules.
	 * 
	 * @param rulePath
	 *            file path to your firewall rules
	 * @param delimiter
	 *            the regular expression separating the values of the firewall
	 *            rule. Enter null if it is a ",".
	 */
	public static ArrayList<String[]> getContents(String rulePath, String delimiter) {
		ArrayList<String[]> rules = new ArrayList<String[]>();
		try {
			Scanner s = new Scanner(new File(rulePath));
			while (s.hasNext()) {
				String r = s.nextLine();
				String[] rule = new String[0];
				if (delimiter == null)
					rule = r.split(",");
				else
					rule = r.split(delimiter);
				rules.add(rule);
			}
			s.close();
		} catch (FileNotFoundException e) {
			System.err.println("File " + rulePath + " not found!");
		}
		return rules;
	}
}
